<template>
	<view>
		<u-navbar title="积分中心" :autoBack="true" :bgColor="theme_color" :titleStyle="{color:'#ffffff'}"
			leftIconColor="#ffffff"></u-navbar>
		<view class="integral-details bg-white" :style="'margin-top:' + navH + 'px;'">
			<view class='header'>
				<view class='currentScore'>当前积分</view>
				<view class="scoreNum">{{parseInt(walletInfo.pay_points) || 0}}</view>
				<view class='line'></view>
				<!-- <view class='nav acea-row'>
					<view class='item'>
						<view class='num'>{{walletInfo.sum_integral || 0}}</view>
						<view>累计积分</view>
					</view>
					<view class='item'>
						<view class='num'>{{walletInfo.deduction_integral || 0}}</view>
						<view>累计消费</view>
					</view>
					<view class='item'>
						<view class='num'>{{walletInfo.frozen_money || 0}}</view>
						<view>冻结积分</view>
					</view>
				</view> -->
				<view class="apply">
					<view>
						<navigator url='/pages/users/privacy/index?type=6' hover-class="none">
							<view>积分规则</view>
						</navigator>
					</view>
				</view>
			</view>
			<view class='wrapper'>
				<view class='nav acea-row'>
					<view class='item acea-row row-center-wrapper' :class='current==index?"on":""'
						v-for="(item,index) in navList" :key='index' @click='nav(index)'><text class='iconfont'
							:class="item.icon"></text>{{item.name}}</view>
				</view>
				<view class='list' :hidden='current!=0'>
					<!-- <view class='tip acea-row row-middle'>
						<text class='iconfont icon-shuoming'></text>提示：积分数值的高低会直接影响您的会员等级
					</view> -->
					<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
						<view class='item acea-row row-between-wrapper' v-for="(item,index) in integralList"
							:key="index">
							<view>
								<view class='state'>{{item.change_desc}}</view>
								<view>{{item.change_type || ''}}</view>
								<view>{{item.change_time}}</view>
							</view>
							<view class='num'>{{item.pay_points}}</view>
							<!-- <view class='num font-color' v-if="item.pm">+{{item.number}}</view>
							<view class='num' v-else>-{{item.number}}</view> -->
						</view>
					</mescroll-body>

				</view>
				<view class='list2' :hidden='current!=1'>
					<navigator class='item acea-row row-between-wrapper' hover-class='none' 
						url='/pages/users/user_integral/integral_shop/index'>
						<view class='pictrue'>
							<image :src="ima_url+'/statics/system_images/score.png'"></image>
						</view>
						<view class='name'>积分商城</view>
						<view class='earn'>去兑换</view>
					</navigator>
				<!-- 	<navigator class='item acea-row row-between-wrapper' hover-class='none'
						url='/pages/users/user_sgin/index'>
						<view class='pictrue'>
							<image :src="ima_url+'/statics/system_images/score.png'"></image>
						</view>
						<view class='name'>每日签到可获得积分奖励</view>
						<view class='earn'>赚积分</view>
					</navigator> -->
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		wallet,
		score_list
	} from '@/api/user.js'
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import {
		BASE_URL
	} from '@/config/app';

	export default {
		components: {

		},
		mixins: [MescrollMixin],
		data() {
			return {
				ima_url: BASE_URL,
				theme_color: getApp().globalData.theme_color,
				walletInfo: {},
				navH: '',
				navList: [{
						'name': '分值明细',
						'icon': 'icon-mingxi'
					},
					{
						'name': '积分商城',
						'icon': 'icon-tishengfenzhi'
					}
				],
				current: 0,
				integralList: [],
				type: '', //1收入2支出 空为全部	
			};
		},
		computed: mapGetters(['isLogin', 'app_token']),
		onLoad() {
			this.navH = getApp().globalData.navHeight / 2 - 5;
			if (this.isLogin) {
				this.getWallet();
			} else {
				toLogin();
			}
		},

		methods: {
			getWallet: function() {
				let that = this;
				wallet({
					app_token: that.app_token
				}).then(res => {
					that.$set(that, 'walletInfo', res.data);
				});
			},
			nav: function(current) {
				this.current = current;
			},
			upCallback(page) {
				var that = this;
				score_list({
					app_token: that.app_token,
					page: page.num,
					type: that.type
				}).then(async (res) => {
					this.mescroll.endSuccess(res.data.length);

					//设置列表数据
					if (page.num == 1) this.integralList = []; //如果是第一页需手动制空列表
					this.integralList = this.integralList.concat(res.data); //追加新数据

				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	/deep/ .mescroll-body{
		min-height: 400px!important;
	}
	.integral-details{
		border-top:1px solid white;
	}
	.integral-details .header {
		// background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 460rpx;
		font-size: 72rpx;
		color: #fff;
		padding: 31rpx 0 45rpx 0;
		box-sizing: border-box;
		text-align: center;
		font-family: 'Guildford Pro';
		background-color: $theme-color;
	}

	.integral-details .header .currentScore {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.8);
		text-align: center;
		margin-bottom: 11rpx;
	}

	.integral-details .header .scoreNum {
		font-family: "Guildford Pro";
	}

	.integral-details .header .line {
		width: 60rpx;
		height: 3rpx;
		background-color: #fff;
		margin: 20rpx auto 0 auto;
	}

	.integral-details .header .nav {
		font-size: 22rpx;
		color: rgba(255, 255, 255, 0.8);
		flex: 1;
		margin-top: 35rpx;
	}

	.integral-details .header .nav .item {
		width: 33.33%;
		text-align: center;
	}

	.integral-details .header .nav .item .num {
		color: #fff;
		font-size: 40rpx;
		margin-bottom: 5rpx;
		font-family: 'Guildford Pro';
	}

	.integral-details .wrapper .nav {
		flex: 1;
		width: 690rpx;
		border-radius: 20rpx 20rpx 0 0;
		margin: -96rpx auto 0 auto;
		background-color: #f7f7f7;
		height: 96rpx;
		font-size: 30rpx;
		color: #bbb;
	}

	.integral-details .wrapper .nav .item {
		text-align: center;
		width: 50%;
	}

	.integral-details .wrapper .nav .item.on {
		background-color: #fff;
		color: $theme-color;
		font-weight: bold;
		border-radius: 20rpx 0 0 0;
	}

	.integral-details .wrapper .nav .item:nth-of-type(2).on {
		border-radius: 0 20rpx 0 0;
	}

	.integral-details .wrapper .nav .item .iconfont {
		font-size: 38rpx;
		margin-right: 10rpx;
	}

	.integral-details .wrapper .list {
		background-color: #fff;
		padding: 24rpx 30rpx;
	}

	.integral-details .wrapper .list .tip {
		font-size: 25rpx;
		width: 690rpx;
		height: 60rpx;
		border-radius: 50rpx;
		background-color: #fff5e2;
		border: 1rpx solid #ffeac1;
		color: #c8a86b;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
	}

	.integral-details .wrapper .list .tip .iconfont {
		font-size: 35rpx;
		margin-right: 15rpx;
	}

	.integral-details .wrapper .list .item {
		height: 124rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 24rpx;
		color: #999;
	}

	.integral-details .wrapper .list .item .state {
		font-size: 28rpx;
		color: #282828;
		margin-bottom: 8rpx;
	}

	.integral-details .wrapper .list .item .num {
		font-size: 36rpx;
		font-family: 'Guildford Pro';
		color: #ff0000;
	}

	.integral-details .wrapper .list .item .num.font-color {
		color: #E93323 !important;
	}

	.integral-details .wrapper .list2 {
		background-color: #fff;
		padding: 24rpx 0;
	}

	.integral-details .wrapper .list2 .item {
		background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
		width: 690rpx;
		height: 180rpx;
		position: relative;
		border-radius: 10rpx;
		margin: 0 auto 20rpx auto;
		padding: 0 25rpx 0 180rpx;
		box-sizing: border-box;
	}

	.integral-details .wrapper .list2 .item .pictrue {
		width: 90rpx;
		height: 150rpx;
		position: absolute;
		bottom: 0;
		left: 45rpx;
	}

	.integral-details .wrapper .list2 .item .pictrue image {
		width: 100%;
		height: 100%;
	}

	.integral-details .wrapper .list2 .item .name {
		width: 285rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #c8a86b;
	}

	.integral-details .wrapper .list2 .item .earn {
		font-size: 26rpx;
		color: #c8a86b;
		border: 2rpx solid #c8a86b;
		text-align: center;
		line-height: 52rpx;
		height: 52rpx;
		width: 160rpx;
		border-radius: 50rpx;
	}

	.apply {
		top: 52rpx;
		right: 0;
		position: absolute;
		width: max-content;
		height: 56rpx;
		padding: 0 14rpx;
		background-color: #fff1db;
		color: #a56a15;
		font-size: 22rpx;
		border-radius: 30rpx 0 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
